<template>
  <div class="table-wrap">
    <div class="search_header">
      <!-- <el-button icon="el-icon-plus" @click="addProject"
        >新增项目</el-button
      > -->
      <div></div>
      <div class="search_header_right">
        <!-- <el-select
          placeholder="规划用地性质"
          v-model="parameter.ghydxz"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in landUsageOptions"
            :key="item.dictValue"
            :label="item.dictText"
            :value="item.dictValue"
          >
          </el-option>
        </el-select> -->
        <el-select
          placeholder="项目类型"
          v-model="parameter.xmlx"
          clearable
          @change="getList"
        >
          <el-option
            v-for="item in xmlxOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="项目是否涉密"
          v-model="parameter.xmsfsm"
          clearable
          @change="getList"
        >
          <el-option
            v-for="item in xmsfsmOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-input
          placeholder="请输入综合编号、项目名称"
          v-model="parameter.keyWord"
          @keydown.enter.native="search"
          clearable
        >
          <span
            @click="search"
            slot="suffix"
            style="display: inline-block"
          >
            <Icon
              title="搜索"
              name="sousuo"
              color="#A7ADB5"
              font-size="20"
            />
          </span>
        </el-input>
      </div>
    </div>
    <el-table
      :data="projectList"
      :header-cell-style="{
        background: '#F2F6FB ',
        color: ' #6B767D'
      }"
      border
      :row-class-name="tableRowClassName"
      v-loading="loading"
    >
      <el-table-column
        label="序号"
        align="center"
        show-overflow-tooltip
        width="80"
      >
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="项目名称"
        prop="projectName"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目编号"
        prop="projectNo"
        show-overflow-tooltip
      />
      <el-table-column
        label="固定资产投资项目代码"
        prop="gdzctzxmdm"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目类型"
        prop="xmlxText"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目立项层级"
        prop="xmlxcjText"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目是否涉密"
        prop="xmsfsmText"
        show-overflow-tooltip
      />
      <el-table-column
        label="所在区域"
        prop="areaText"
        show-overflow-tooltip
      />
      <el-table-column
        label="用地位置"
        prop="address"
        show-overflow-tooltip
      />
      <el-table-column
        label="更新时间"
        prop="updateTime"
        show-overflow-tooltip
      />
      <el-table-column
        label="状态"
        prop="statusText"
        show-overflow-tooltip
      />
      <el-table-column
        label="操作"
        show-overflow-tooltip
        width="120"
      >
        <template slot-scope="scope">
          <el-button
            @click="viewProject(scope.row)"
            type="text"
            style="color: #00baff; font-weight: 400"
            >查看</el-button
          >
          <el-button
            @click="updateProgress(scope.row)"
            type="text"
            style="color: #00baff; font-weight: 400"
            v-has="'EngineeringConstructionPermit:edit'"
            >编辑</el-button
          >
          <!-- <el-button
            @click="deleteProject(scope.row)"
            type="text"
            style="color: #ff5b5b; font-weight: 400"
            >删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <div class="table-pagination" v-if="total">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="parameter.pageSize"
        @current-change="pageChange"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  queryProjectList,
  deleteProjectInfo
} from '@/api/landPlan'
import { getDictOptions } from '@/utils/dict'
import Icon from '@/components/icon'
import { getList } from '@/api/gcjsxk'
import { queryOptions } from '@/api/dict'
export default {
  name: 'index',
  components: {
    Icon
  },
  data() {
    return {
      projectList: [],
      total: '',
      parameter: {
        xmsfsm: '',
        xmlx: '',
        keyWord: '',
        pageIndex: 1,
        pageSize: 10
      },
      xmlxOptions: [],
      xmsfsmOptions: [],
      landUsageOptions: [],
      supportWayOptions: [],
      loading: false
    }
  },
  mounted() {
    this.initOptions()
    this.getList()
  },
  async created() {
    await this.getxmlxOption()
    await this.getxmsfsmOption()
  },
  methods: {
    async initOptions() {
      const data = await getDictOptions('ydxz,gdfs')
      this.landUsageOptions = data[0].resourceDictItems
      this.supportWayOptions = data[1].resourceDictItems
    },
    // 项目类型
    getxmlxOption() {
      queryOptions('zhgh_xmfl_jz').then((res) => {
        if (res.success) {
          this.xmlxOptions = res.data.map((item) => {
            return {
              label: item.dictText,
              value: item.dictValue
            }
          })
        }
      })
    },
    // 项目是否涉密
    getxmsfsmOption() {
      queryOptions('zhgh_xmsfsm').then((res) => {
        if (res.success) {
          this.xmsfsmOptions = res.data.map((item) => {
            return {
              label: item.dictText,
              value: item.dictValue
            }
          })
        }
      })
    },
    search() {
      this.parameter.pageIndex = 1
      this.getList()
    },

    pageChange(page) {
      this.parameter.pageIndex = page
      this.getList()
    },

    // 获取用户列表
    getList() {
      this.loading = true
      getList(this.parameter).then((res) => {
        if (res.success) {
          this.total = res.data.count
          this.projectList = res.data.list
        }
        this.loading = false
      })
    },

    // 表格高亮
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'light'
      } else {
        return ''
      }
    },

    addProject() {
      this.$router.push({
        path: '/wisdomPlanning/housingProjectManagement/EngineeringConstructionPermit/formPage',
        query: {
          type: 'add',
          defaultIndex: 3
        }
      })
    },

    // 进度更新
    updateProgress(row) {
      this.$router.push({
        path: '/wisdomPlanning/housingProjectManagement/EngineeringConstructionPermit/formPage',
        query: {
          pkid: row.pkid,
          type: 'edit',
          defaultIndex: 3
        }
      })
    },
    // 项目查看
    viewProject(row) {
      this.$router.push({
        path: '/wisdomPlanning/housingProjectManagement/EngineeringConstructionPermit/formPage',
        query: {
          pkid: row.pkid,
          type: 'detail',
          defaultIndex: 3
        }
      })
    },

    // 删除项目
    deleteProject(row) {
      this.$confirm(
        '此操作将永久删除该基础要素信息，是否继续?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(() => {
          delBasicList({ pkid: row.pkid }).then((res) => {
            if (res.success) {
              this.$message.success('删除成功')
              if (
                this.total % 10 === 1 &&
                this.parameter.pageIndex ===
                  parseInt(this.total / 10) + 1 &&
                this.parameter.pageIndex !== 1
              ) {
                this.parameter.pageIndex -= 1
              }
              this.getList()
            } else {
              this.$message.error(res.message)
            }
          })
        })
        .catch((error) => {
          this.$message.info('已取消删除')
        })
    }
  }
}
</script>

<style scoped lang="scss">
@import '~@/assets/css/table.scss';
</style>
